<?php
if (! defined ( 'IN_JISHIGOU' )) {
	exit ( 'invalid request' );
}
class ModuleObject extends MasterObject {
	function ModuleObject($config) {
		$this->MasterObject ( $config );
		$this->Execute ();
	}
	function Execute() {
		switch ($this->Code) {
			case 'info' :
				{
					$this->getinfo ();
					break;
				}
			default :
				{
					$this->Main ();
					break;
				}
		}
	}
	function Main() {
		api_output ( 'test api is ok' );
	}
	function getinfo() {
		$uid = max ( 0, ( int ) $this->Inputs ['uid'] );
		$user = array ();
		if ($uid) {
			$user = $this->_init_user ( $uid );
		} else {
			$username = trim ( $this->__API__ ['username'] );
			$password = trim ( $this->__API__ ['password'] );
			if ($username && $password) {
				$user = $this->DatabaseHandler->FetchFirst ( "select * from " . TABLE_PREFIX . "members where `nickname`='{$username}'" );
				if ((md5 ( $user ['nickname'] . $user ['password'] ) != $password) && (md5 ( array_iconv ( $this->Config ['charset'], API_INPUT_CHARSET, $user ['nickname'] ) . $user ['password'] ) != $password)) {
					$user = array ();
				}
			}
		}
		$outstr = array (
				'site_name' => $this->Config ['site_name'],
				'site_url' => $this->Config ['site_url'],
				'ajax_time' => $this->Config ['ajax_topic_time'],
				'changeword' => $this->Config ['changeword'],
				'uc_face' => $this->Config ['ucenter_enable'] && $this->Config ['ucenter'] ['face'] ? 1 : 0,
				'user_role' => array (
						'role_id' => $user ['role_id'],
						'role_type' => $user ['role_type'] 
				),
				'regstatus' => implode ( ',', $this->Config ['regstatus'] ),
				'channel_must' => $this->Config ['channel_must'] ? 1 : 0 
		);
		unset ( $user );
		api_output ( $outstr );
	}
}
